package com.controller.user;

import com.proj.model.ResultModel;
import com.proj.service.SearchService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/** 商品查询controller */
@RestController
@CrossOrigin
public class SearchController {
  @Autowired private SearchService searchService;

  @GetMapping("/searchGoods")
  public ResultModel GoodsSearch(
      @RequestParam("productName") String productName,
      @RequestParam(value = "fromPrice", defaultValue = "0") String fromPrice,
      @RequestParam(value = "toPrice", defaultValue = "1000000") String toPrice,
      String categoryId,
      String userId,
      @RequestParam(value = "fromUpdateTime", defaultValue = "2000/01/01") String fromUpdateTime,
      @RequestParam(value = "toUpdateTime", defaultValue = "2025/01/01") String toUpdateTime,
      @RequestParam(value = "fromPublicaDate", defaultValue = "1900/01/01") String fromPublicDate,
      @RequestParam(value = "toPublicDate", defaultValue = "2025/01/01") String toPublicDate,
      String author,
      String appearance,
      String pressHorse,
      String sort,
      @RequestParam("pageIndex") Integer pageIndex,
      @RequestParam("pageSize") Integer pageSize,
      String stylePrefix,
      String styleSuffix)
      throws Exception {
    // 调用service查询商品列表
    ResultModel resultModel =
        searchService.queryGoods(
            productName,
            fromPrice,
            toPrice,
            categoryId,
            userId,
            fromUpdateTime,
            toUpdateTime,
            fromPublicDate,
            toPublicDate,
            author,
            appearance,
            pressHorse,
            sort,
            pageIndex,
            pageSize,
            stylePrefix,
            styleSuffix);

    return resultModel;
  }
}
